package com.mdd.front.controller.car;

import com.alipay.api.AlipayApiException;
import com.mdd.common.aop.NotLogin;
import com.mdd.common.aop.NotPower;
import com.mdd.common.base.page.PageValidate;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.enums.ErrorEnum;
import com.mdd.common.exception.OperateException;
import com.mdd.common.validator.annotation.IDMust;
import com.mdd.front.service.IUserOrderService;
import com.mdd.front.validate.car.order.CarOrderCreateValidate;
import com.mdd.front.validate.common.IdValidate;
import com.mdd.front.validate.order.OrderClueCreateValidate;
import com.mdd.front.validate.order.OrderCreateValidate;
import com.mdd.front.vo.car.CarOrderDetailVo;
import com.mdd.front.vo.car.CarOrderInfoListedVo;
import com.mdd.front.vo.order.OrderInfoDetailVo;
import com.mdd.front.vo.order.OrderInfoListedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 订单
 * <p>
 * {@code @Description}
 * {@code @Author} 幻速
 * {@code @Date} 2023/11/1 17:44
 **/
@RestController
@RequestMapping("/api/front/car/order")
@Api(tags = "我的订单")
public class CarOrderController {
    @Resource
    IUserOrderService iOrderService;
    //订单列表
    @GetMapping("/list")
    public AjaxResult<PageResult<CarOrderInfoListedVo>> list(@Validated PageValidate pageValidate, @RequestParam(name = "status", required = false) Integer status, @RequestParam(name = "type", required = true) Integer type){
        return AjaxResult.success(iOrderService.carOrderPage(status,type,pageValidate));
    }


    //订单详情
    @GetMapping("/detail")
    public AjaxResult detail(@Validated @IDMust() @RequestParam("orderId") Long orderId){
        return AjaxResult.success(iOrderService.carOrderDetail(orderId));
    }

    @NotPower
    @PostMapping("/addDepositOrder")
    @ApiOperation(value="押金支付（零售）")
    public AjaxResult<Object> addDepositOrder(@Validated @RequestBody CarOrderCreateValidate carOrderCreateValidate) throws AlipayApiException {
        return new AjaxResult<>(ErrorEnum.SUCCESS.getCode(), ErrorEnum.SUCCESS.getMsg(), iOrderService.addDepositOrder(carOrderCreateValidate)) ;
    }
    //取消订单
    @GetMapping("/cancel")
    public AjaxResult<Object> cancel(@Validated @IDMust() @RequestParam("orderId") Long orderId) throws AlipayApiException {
          iOrderService.cancelCarOrder(orderId);
        return AjaxResult.success();
    }

    //订单退款
    @GetMapping("/refund")
    public AjaxResult<Object> refund(@Validated @IDMust() @RequestParam("orderId") Long orderId) throws AlipayApiException {
        iOrderService.refundCarOrde(orderId);
        return AjaxResult.success();
    }
}
